package svgedit.TestSVG;

import static org.junit.Assert.assertTrue;
import org.junit.Test;
import svgedit.gui.Frame;
import svgedit.svg.SVGDocument;
import svgedit.svg.SVGGroup;
import svgedit.svg.SVGLineElement;
import svgundoredo.DeleteElementCommand;

/**
 * test DeleteElementCommand class
 */
public class DeleteElementCommandTest
{
    
    /**
     * test execute() method
     */
    @Test
    public void testexecute()
    {
        // create new frame
        Frame frame = new Frame();
        SVGDocument document;
        document = frame.getDocument();
        SVGLineElement child = new SVGLineElement(document);
        SVGGroup parent = new SVGGroup(document);
        parent.appendChild(child);
        DeleteElementCommand delete = new DeleteElementCommand(parent, child);
        assertTrue(parent.getChildren().length == 1);
        delete.execute();
        // test the element is deleted
        assertTrue(parent.getChildren().length == 0);
        
    }
    
    /**
     * test undo() method
     */
    @Test
    public void testundo()
    {
        // create new frame
        Frame frame = new Frame();
        SVGDocument document;
        document = frame.getDocument();
        SVGLineElement child = new SVGLineElement(document);
        SVGGroup parent = new SVGGroup(document);
        parent.appendChild(child);
        DeleteElementCommand delete = new DeleteElementCommand(parent, child);
        assertTrue(parent.getChildren().length == 1);
        delete.execute();
        // test the element is deleted
        assertTrue(parent.getChildren().length == 0);
        delete.undo();
        // test the delete has been undo
        assertTrue(parent.getChildren().length == 1);
        
    }
}
